<template>
  <div class="index listDet">
    <Header></Header>
    <div class="main" style="min-height: 100%;padding-top: 60px">
      <p class="current-nav">
        当前位置 :
        <router-link to="homePage">首页</router-link>
        <i>></i>应急资讯
      </p>
      <div class="listDetMain" style="height: 100%">
        <div class="clearfix">
          <el-button class="btn" style="margin-top: 20px"  @click.stop="back"><i class="el-icon-back"> 返回</i></el-button>
        </div>
        <div class="clearfix">
          <span class="fr downBtn" @click="downloadmsg"><i class="el-icon-download"> 下载</i></span>
        </div>
         <div class="article">
          <h2 >{{content.lawName}}</h2>
          <h5 >发布日期：{{content.effectiveTime|timeBy}}</h5>
           <h5 v-if="content.fileUrlList" v-for="(val, key, i) in content.fileUrlList" :key="i">
             <iframe v-if="content.fileUrlList&&content.fileUrlList[0]" :src="content.fileUrlList[0].viewUrl" style="height: 800px;width: 100%;border: 0"></iframe>
           </h5>
          <!--<p  v-html='content.description'></p>-->
        </div>
      </div>
    </div>
    <Footer></Footer>
  </div>
</template>

<script>
  import config from "../../config.js";
  import Header from '../common/header3'
  import Footer from '../common/footer'

  export default {
    data() {
      return {
        content:{},
        list: [],
        url: '',
        type: "",
        newsList1: [],      }
    },
    components: {
      Header,
      Footer
    },
    mounted() {

      this.getDetail()
    },
    methods: {
      back(){
        this.$router.go(-1)
      },
      getDetail() {
        this.$axios.post(config.baseUrl + '/emergency/v1.0/index/law/info/' + this.$route.query.id, {}).then((res) => {
          if (res.data.meta.success) {
            this.content = res.data.data
          } else {

          }

        }).catch((response) => {
          console.log(response);
        })
      },
      downloadmsg() {
        /*       var timestamp = Date.parse(new Date());
               var save_link = document.createElementNS('http://www.w3.org/1999/xhtml', 'a');
               save_link.href = this.content.fileJson
               save_link.download = timestamp;
               var event = document.createEvent('MouseEvents');
               event.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
               save_link.di spatchEvent(event);*/

        if (this.content.fileUrlList) {
          var arr=[];
          for(var obj of this.content.fileUrlList){
            arr.push(JSON.parse(obj.fileJson))
          }
          if(arr.length==0){
            this.$message({
              message: "无附件",
              type: "error"
            });
          }
          this.$axios({
            method: "post",
            responseType: 'blob',//防止返回乱码
            url: this.$baseUrl + "emergency/v1.0/download/file",
            data: {fileList:arr}
          }).then((res) => {
            if (res.status == 200) {
              const data = res.data;
              const blob = new Blob([data], { type: "application/zip" });
              const blobUrl = window.URL.createObjectURL(blob);
              this.download(blobUrl);
            } else {
              this.$message({
                message: '导出失败！',
                type: "error"
              });
            }
        /*    if (res.data.meta.success) {
              var timestamp = Date.parse(new Date());
              const content = res.data;
              const blob = new Blob([content]);
              const filename = timestamp + ".xls";
              if ("download" in document.createElement("a")) {
                // 非IE下载
                const elink = document.createElement("a");
                elink.download = filename;
                elink.style.display = "none";
                elink.href = URL.createObjectURL(blob);
                document.body.appendChild(elink);
                elink.click();
                URL.revokeObjectURL(elink.href); // 释放URL 对象
                document.body.removeChild(elink);
              } else {
                // IE10+下载
                navigator.msSaveBlob(blob, filename);
              }
            } else {

            }*/

          }).catch((response) => {
            console.log(response);
          })
        } else {
          this.$message({
            message: "无附件",
            type: "error"
          });
        }
      },
      download(blobUrl) {
        const a = document.createElement('a');
        a.style.display = 'none';
        a.download = '法规压缩文件';
        a.href = blobUrl;
        a.click();
      },


    },
    created() {
      // this.getDetail()
    },
    filters: {
      timeBy(val) {
        if (val) {
          return val.substring(0, 10)
        }
      },
    }
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang='less' scoped>
  .listDet {
    .current-nav {
      float: left;
      width: 100%;
      height: 40px;
      line-height: 40px;
      padding-left: 30px;
      color: #939393;
      font-size: 14px;
      a {
        color: #333!important;
        font-size: 14px;
      }
      i {
        margin: 0 10px;
        font-style: normal;
      }
    }
    .downBtn {
      display: inline-block;
      width: 100px;
      height: 35px;
      background: #5496ff;
      color: #fff;
      border-radius: 10px;
      text-align: center;
      line-height: 35px;
      margin-top: 30px;
      cursor: pointer;
    }
    .listDetMain {
      padding: 0 130px;
      background: #fff;
      width: calc(100% - 60px);
      margin: 40px auto 0;
      border-radius: 4px;
      .article {
        padding-top: 80px;
        padding-bottom: 40px;
        width: 65%;
        margin: 0 auto;
        h2 {
          font-size: 18px;
          font-weight: bold;
          text-align: center;
        }
        h5 {
          color: #999;
          font-size: 12px;
          text-align: center;
          margin: 20px 0 30px;
        }
        p {
          text-indent: 2em;
          line-height: 22px;
        }
      }
    }
  }

</style>
<style lang='less'>
  img{ max-width: 100%}
</style>
